import json
from models import BaseModels
from sqlalchemy import Column, String, JSON, BigInteger, DateTime, Integer, ForeignKey


# 选择流程
class Routes(BaseModels):
    __tablename__ = 'routes'
    id = Column(BigInteger, autoincrement=True, primary_key=True, unique=True, nullable=False)
    name = Column(String(64), nullable=False, unique=True, comment="路线名字")
    route = Column(JSON, nullable=False, comment="生产路线")
    user_id = Column(Integer, ForeignKey("users.id"), comment="对应用户ID")
    time = Column(DateTime, nullable=False, comment="路线创建时间")

    def __repr__(self):
        return json.dumps({
            "route_id": self.id,
            "name": self.name,
            "user_id": self.user_id,
            "time": self.time.strftime("%Y-%m-%d %H:%M:%S") if self.time else None
        })
